/*
 * dl.h
 *
 *  Created on: 24/giu/2014
 *      Author: Pasquale
 */

#ifndef DL_H_
#define DL_H_

#include "nRF24L01P.h"

/* Dimensioni Pacchetto DL e Frame */
#define MAX_DL_LENGTH 		1920
#define PAYLOAD_DL_LENGTH  	29
#define HEADER_DL_LENGTH    3
#define FRAGNUM_MASK		0x3f

/* Offset Header */
#define DEST_ADDR_OFFSET	0
#define FRAM_NUM_OFFSET		1
#define RESERVED_OFFSET		2
#define LENGTH_MSB_OFF		3
#define LENGTH_LSB_OFF		4

/* TxPacket Result */
#define SUCCESS				0
#define FRAME_LOST			1
#define LENGTH_ERROR		2

/* RxPacket Result */
#define REFUSED				2
#define PROCESSED			1
#define	ACCEPTED			0


void init_dl();
void resetBuffer(uint8_t* pbuff, uint16_t length);
void printBuffer(uint8_t* pbuff, uint16_t length);
void preparePayload(uint8_t* packTx, uint8_t* pdata, uint8_t header_length, uint8_t max, uint8_t dataOffset);
void stripPayload(uint8_t* buffDest, uint8_t* buffSource, uint8_t offsetDest, uint8_t offsetSource, uint8_t numByte);
uint8_t TxPacket(uint8_t* pdata, uint16_t length, uint8_t destAddress);
uint8_t RxFrame(uint8_t* pdata, uint8_t length);
uint8_t RxPacket(uint8_t* pdata, uint8_t sourceAddress);

#endif /* DL_H_ */
